package com.noble.meether.ui.point;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.noble.meether.R;
import com.noble.glamour.bean.center.user.detail.UserDetail;
import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.glamour.module.logic.config.UrlParam;
import com.noble.glamour.module.logic.request.HttpResponse;
import com.noble.glamour.module.logic.request.RequestComplete;
import com.noble.library.base.BaseAppCompatActivity;
import com.noble.meether.ui.point.adapter.MyPointAdapter;
import com.noble.meether.ui.point.bean.PointList;

/**
 * 我的指标
 */
public class MyPointAct extends BaseAppCompatActivity implements RequestComplete {
    private MyPointAdapter pointAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_point_act);
        initView();
    }

    @Override
    protected boolean isStatusBarLight() {
        return false;
    }

    private void initTitle() {
        setTitleBackground(getResources().getColor(R.color.transparent));
        setBackView(false);
        setTitle("我的指标", getResources().getColor(R.color.white));
    }

    private void initView() {
        initTitle();
        TextView my_point = findViewById(R.id.my_point);
        TextView my_award = findViewById(R.id.my_award);
        UserDetail userDetail = ModuleMgr.getCenterMgr().getMyInfo();
        my_point.setText(String.valueOf(userDetail.getStar()));
        my_award.setText(String.valueOf(userDetail.getAmountStar()));

        RecyclerView rlvList = findViewById(R.id.recycler_view);
        rlvList.setLayoutManager(new LinearLayoutManager(this));
        pointAdapter = new MyPointAdapter(this);
        rlvList.setAdapter(pointAdapter);
        ModuleMgr.getCommonMgr().reqSysAward(this);
    }

    @Override
    public void onRequestComplete(HttpResponse response) {
        if (response.getUrlParam() == UrlParam.reqSysAward) {
            if (!response.isOk()) return;
            PointList pointList = (PointList) response.getBaseData();
            if (pointList.getPointList().size() <= 0) return;
            pointAdapter.setList(pointList.getPointList());
        }
    }
}